﻿#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int map[8][8] = {
	1,1,1,1,1,1,1,1,
	1,3,4,0,0,0,1,1,
	1,0,1,1,1,0,1,1,
	1,0,0,5,0,0,0,1,
	1,0,1,0,1,0,1,1,
	1,0,1,0,1,0,1,1,
	1,0,0,0,4,3,0,1,
	1,1,1,1,1,1,1,1
};
void drawMap() {
	for (int i = 0;i < 8;i++) {
		for (int j = 0;j < 8;j++) {
			switch (map[i][j]) {
			case 0:
				printf("  ");
				break;
			case 1:
				printf("■");
				break;
			case 3:
				printf("☆");
				break;
			case 4:
				printf("★");
				break;
			case 5:
			case 8:
				printf("※");
				break;
			case 7:
				printf("●");
				break;
			}
		}
		printf("\n");
	}
}
int getRow() {
	for (int i = 0;i < 8;i++) {
		for (int j = 0;j < 8;j++) {
			if (map[i][j] == 5 || map[i][j] == 8) {
				return i;
			}
		}
	}
	return -1;
}
int getCols() {
	for (int i = 0;i < 8;i++) {
		for (int j = 0;j < 8;j++) {
			if (map[i][j] == 5 || map[i][j] == 8) {
				return j;
			}
		}
	}
	return -1;
}
void keydown() {
	char userKey = _getch();
	int i = getRow();
	int j = getCols();
	switch (userKey) {
	case 'w':
	case'W':
	case 72:
		if (map[i - 1][j] == 0 || map[i - 1][j] == 3) {
			map[i][j]-= 5;
			map[i - 1][j]+= 5;
		}
		if (map[i - 1][j] == 4 || map[i - 1][j] == 7) {
			if (map[i - 2][j] == 0 || map[i - 2][j] == 3) {
				map[i][j] -= 5;
				map[i - 1][j] += 1;
				map[i - 2][j] += 4;
			}
		}
		break;
	case's':
	case'S':
	case 80:
		if (map[i + 1][j] == 0 || map[i + 1][j] == 3) {
			map[i][j]-= 5;
			map[i + 1][j]+= 5;
		}
		if (map[i + 1][j] == 4 || map[i + 1][j] == 7) {
			if (map[i + 2][j] == 0 || map[i + 2][j] == 3) {
				map[i][j] -= 5;
				map[i + 1][j] += 1;
				map[i + 2][j] += 4;
			}
		}
		break;
	case'a':
	case'A':
	case'75':
		if (map[i][j-1] == 0 || map[i][j-1] == 3) {
			map[i][j]-= 5;
			map[i][j-1]+= 5;
		}
		if (map[i][j-1] == 4 || map[i][j-1] == 7) {
			if (map[i][j-2] == 0 || map[i][j-2] == 3) {
				map[i][j] -= 5;
				map[i][j-1] += 1;
				map[i][j-2] += 4;
			}
		}
		break;
	case'd':
	case'D':
	case 77:
		if (map[i][j +1] == 0 || map[i][j + 1] == 3) {
			map[i][j]-= 5;
			map[i][j + 1]+= 5;
		}
		if (map[i][j + 1] == 4 || map[i][j +1] == 7) {
			if (map[i][j + 2] == 0 || map[i][j + 2] == 3) {
				map[i][j] -= 5;
				map[i][j + 1] += 1;
				map[i][j + 2] += 4;
			}
		}
		break;
	}
}
int main() {

	while(1){
	drawMap(); 
	keydown();
	system("cls");
	}
		
		
	return 0;
}
